package org.iks.user.web.mapper;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.iks.user.web.entity.FriendEntity;
import org.iks.user.web.vo.UserFriendRespVo;

import java.util.List;

/**
 * Author kzou
 * Date 2024/2/13
 * Description:
 */
@Mapper
public interface FriendMapper extends BaseMapper<FriendEntity> {

    default List<UserFriendRespVo> queryUserFriends(String userAccount){
        LambdaQueryWrapper<FriendEntity> wrapper = new LambdaQueryWrapper<>();
        wrapper
                .eq(FriendEntity::getUserAccount, userAccount)
                .or()
                .eq(FriendEntity::getCreatorAccount, userAccount)
        ;
        List<FriendEntity> friendEntities = selectList(wrapper);
        return friendEntities.stream().map(e -> {
            UserFriendRespVo respVo = new UserFriendRespVo();
            respVo.setId(e.getId());
            respVo.setFriendNote(e.getFriendNote());
            respVo.setApplyNote(e.getApplyNote());
            respVo.setUserAccount(e.getUserAccount());
            respVo.setCreatorAccount(e.getCreatorAccount());
            respVo.setApplySourceType(e.getApplySourceType());
            respVo.setCreateTime(e.getCreateTime());
            respVo.setStatus(e.getStatus());
            return respVo;
        }).toList();

    }

}
